﻿import QtQuick 2.0

// 复位状态

Item {

    id: root

    // -1 不用管  0复位完成  1正在复位
    property var resetState_practice: -1
    property var resetState_shifting: -1
    property var resetState_syringe1: -1
    property var resetState_syringe2: -1
    property var resetState_syringe3: -1
    property var resetState_syringe4: -1
    property var resetState_syringe5: -1
    property var resetState_syringe6: -1
    property var resetState_wheel: -1

    property var resetState_purify: {
        if(
            resetState_syringe1 === -1 &&
            resetState_syringe2 === -1 &&
            resetState_syringe3 === -1 &&
            resetState_syringe4 === -1 &&
            resetState_syringe5 === -1 &&
            resetState_syringe6 === -1 &&
            (resetState_wheel === -1 || gCollectContainer !== 0)
        ){
            return -1
        }

        if(
                resetState_syringe1 !== 1 &&
                resetState_syringe2 !== 1 &&
                resetState_syringe3 !== 1 &&
                resetState_syringe4 !== 1 &&
                resetState_syringe5 !== 1 &&
                resetState_syringe6 !== 1 &&
                (resetState_wheel !== 1 || gCollectContainer !== 0)
        ){
            return 0
        }
        return 1
    }



    function startSerial(serial){
        // 开始复位
        if(serial === 0){   // 全部复位
            if(gAppModule === 0){           // 全模块
                resetState_practice = 1
                resetState_shifting = 1
                resetState_syringe1 = 1
                resetState_syringe2 = 1
                resetState_syringe3 = 1
                resetState_syringe4 = 1
                resetState_syringe5 = 1
                resetState_syringe6 = 1
                resetState_wheel    = 1
            }else if(gAppModule === 1){     // 放靶+打靶+转靶模块
                resetState_practice = 1
                resetState_shifting = 1
            }else if(gAppModule === 2){     // 纯化模块
                resetState_syringe1 = 1
                resetState_syringe2 = 1
                resetState_syringe3 = 1
                resetState_syringe4 = 1
                resetState_syringe5 = 1
                resetState_syringe6 = 1
                resetState_wheel    = 1
            }
        }else if(serial === 1){ // 注射器1复位
            resetState_syringe1 = 1
        }else if(serial === 2){ // 注射器2复位
            resetState_syringe2 = 1
        }else if(serial === 3){ // 注射器3复位
            resetState_syringe3 = 1
        }else if(serial === 4){ // 注射器4复位
            resetState_syringe4 = 1
        }else if(serial === 5){ // 注射器5复位
            resetState_syringe5 = 1
        }else if(serial === 6){ // 注射器6复位
            resetState_syringe6 = 1
        }else if(serial === 7){ // 转盘
            resetState_wheel = 1
        }else if(serial === 8){ // 纯化全部
            resetState_syringe1 = 1
            resetState_syringe2 = 1
            resetState_syringe3 = 1
            resetState_syringe4 = 1
            resetState_syringe5 = 1
            resetState_syringe6 = 1
            resetState_wheel    = 1
        }else if(serial === 9){ // 全部注射器
            resetState_syringe1 = 1
            resetState_syringe2 = 1
            resetState_syringe3 = 1
            resetState_syringe4 = 1
            resetState_syringe5 = 1
            resetState_syringe6 = 1
        }else if(serial === 10){ // 放靶 / 转靶
            resetState_shifting = 1
        }else if(serial === 11){    // 打靶
            resetState_practice = 1
        }
    }

    function finishSerial(serial){
        if(serial === 1){               // 注射器
            resetState_syringe1 = 0
        }else if(serial === 2){
            resetState_syringe2 = 0
        }else if(serial === 3){
            resetState_syringe3 = 0
        }else if(serial === 4){
            resetState_syringe4 = 0
        }else if(serial === 5){
            resetState_syringe5 = 0
        }else if(serial === 6){
            resetState_syringe6 = 0
        }else if(serial === 7){
            resetState_wheel    = 0
        }else if(serial === 10){        // 放靶/转靶
            resetState_shifting = 0
        }else if(serial === 11){        // 打靶
            resetState_practice = 0
        }
    }

    function checkResetState(){

        if(gAppModule === 0){
            return ( resetState_practice !== 1 &&
                     resetState_shifting !== 1 &&
                     resetState_syringe1 !== 1 &&
                     resetState_syringe2 !== 1 &&
                     resetState_syringe3 !== 1 &&
                     resetState_syringe4 !== 1 &&
                     resetState_syringe5 !== 1 &&
                     resetState_syringe6 !== 1 &&
                    (resetState_wheel !== 1 || gCollectContainer !== 0))
        }else if(gAppModule === 1){
            return ( resetState_practice !== 1 &&
                     resetState_shifting !== 1 )
        }else if(gAppModule === 2){
            return ( resetState_syringe1 !== 1 &&
                     resetState_syringe2 !== 1 &&
                     resetState_syringe3 !== 1 &&
                     resetState_syringe4 !== 1 &&
                     resetState_syringe5 !== 1 &&
                     resetState_syringe6 !== 1 &&
                    (resetState_wheel !== 1 || gCollectContainer !== 0) )
        }

    }
    function clearResetState(){
        resetState_practice = -1
        resetState_shifting = -1
        resetState_syringe1 = -1
        resetState_syringe2 = -1
        resetState_syringe3 = -1
        resetState_syringe4 = -1
        resetState_syringe5 = -1
        resetState_syringe6 = -1
        resetState_wheel    = -1
    }

}
